<#include "/layout/layout.ftl">
<#import "/layout/macro.ftl" as macro>
<#import "/layout/select.ftl" as my/>
<#assign css>
	<link rel="stylesheet" href="/assets/vendor/bootstrap-datepicker/css/bootstrap-datepicker3.css">
	<style>

	</style>
</#assign>
<#assign js>
	<script src="/assets/vendor/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
	<script type="text/javascript" src="/assets/vendor/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js" charset="UTF-8"></script>
<script>
	function del(id) {
		layer.confirm('确定删除吗?', {icon: 3, title: '提示'}, function (index) {
			$.ajax({
				type: "POST",
				dataType: "json",
				url: "/order/delete/" + id,
				success: function (res) {
					layer.msg(res.message, {time: 2000}, function () {
						location.reload();
					});
				}
			});
		});
	}

	//tableId,queryId,conditionContainer
	//var userTable;
	var winId="userWin";
	$(function() {
	    var thisType = "${orderSearch.type!}";
	    if(thisType){
            initChildType(thisType);
		}
		//Date picker
		$('#datepicker').datepicker({
			autoclose: true,
			format:"yyyy-mm-dd",
			todayHighlight:true,
			language:"zh-CN"
		});
		$('#datepicker-end').datepicker({
			autoclose: true,
			format:"yyyy-mm-dd",
			todayHighlight:true,
			language:"zh-CN"
		});
		$('#datepicker').unbind("change");
		$('#datepicker').change(function(){
			$('#datepicker-end').datepicker('setStartDate', $("#datepicker").val());
		});
		$('#datepicker-end').unbind("change");
		$('#datepicker-end').change(function(){
			$('#datepicker').datepicker('setEndDate', $("#datepicker-end").val());
		});

		//init table and fill data
		//userTable = new CommonTable("user_table", "user_list", "searchDiv");

		//button event
		$('button[data-btn-type]').click(function() {
			var action = $(this).attr('data-btn-type');
			var rowId="ceshi";
			switch (action) {
				case 'add':
					modals.openWin({
						winId:winId,
						title:'新增订单',
						width:'900px',
						url:"/order/edit/ceshi"
					});
					break;
				case 'edit':
					if(!rowId){
						modals.info('请选择要编辑的行');
						return false;
					}
					modals.openWin({
						winId:winId,
						title:'编辑订单【'+userTable.getSelectedRowData().name+'】',
						width:'900px',
						url:"/order/edit/"+rowId,
					});
					break;
				case 'delete':
					if(!rowId){
						modals.info('请选择要删除的行');
						return false;
					}
					modals.confirm("是否要删除该行数据？",function(){
						ajaxPost(basePath+"/order/delete/"+rowId,null,function(data){
							if(data.success){
								//modals.correct("已删除该数据");
								userTable.reloadRowData();
							}else{
								modals.error("订单数据被引用，不可删除！");
							}
						});
					})
					break;
			}

		});
		//form_init();
		// $("#type").change(function(){
		//     var type = $(this).val();
        //     initChildType(type);
		// });


        $("#type").change(function (e){
            var useScope = e.currentTarget.value;
            initChildType(useScope);
        });
	});

    /**
     * 初始化子类型
     * @param type
     */
    function initChildType(type){
        var childType = $("#childType");
        $.ajax({
            type: "GET",
            url: "/agentService/getChildType/"+type,
            dataType: "JSON",
            success: function(res){

                $("#childType option").remove();
                $("#childType").append("<option value=''>请选择</option>");
                for(var key in res.data){
                    $("#childType").append("<option value='"+key+"'>"+res.data[key]+"</option>");
                }

            }
        });
    }
</script>
</#assign>
<@layout title="订单管理" active="order">
<!-- Content Header (Page header) -->

<!-- Main content -->
<section class="content">
	<!-- Default box -->
	<div class="box box-primary">
		<div class="box-header">
			<form class="form-horizontal form-edit" method="post" action="/order/index" id="form">
				<div class="form-group" style="margin-top:10px;">
					<div class="col-sm-2">
						<input  placeholder="请输入分站Id" id="agentId" name="agentId" class="form-control" type="text" value="${orderSearch.agentId!}" >
					</div>
					<div class="col-sm-2">
						<input  placeholder="请输入订单号" id="orderNo" name="orderNo" class="form-control" type="text" value="${orderSearch.orderNo!}" >
					</div>
					<div class="col-sm-2">
						<@my.select id="type" datas=getDict('SERVICE_CLASS')  value="${orderSearch.type!}" defaultValue="请选择订单类型"/>
					</div>
					<div class="col-sm-2 child_type" id="paotui">
						<@my.select id="childType"  datas=getDict('SERVICE_CLASS')  value="${orderSearch.childType!}" defaultValue="请选择订单子类型"/>
					</div>
					<div class="col-sm-2">
						<@my.select id="status" datas=getDict('ORDER_STATUS')  value="${orderSearch.status!}" defaultValue="请选择订单状态"/>
					</div>
				</div>
				<div class="form-group">
					<div class="col-sm-2">
						<@my.select id="payType" datas=getDict('PAY_TYPE')  value="${orderSearch.payType!}" defaultValue="请选择支付方式"/>
					</div>
					<div class="col-sm-2">
						<div class="input-group date">
							<div class="input-group-addon">
								<i class="fa fa-calendar"></i>
							</div>
							<input type="text" placeholder="开始日期" name="startDate" class="form-control pull-right" id="datepicker" value="${(orderSearch.startDate?string('yyyy-MM-dd'))!}">
						</div>
					</div>
					<div class="col-sm-2">
						<div class="input-group date">
							<div class="input-group-addon">
								<i class="fa fa-calendar"></i>
							</div>
							<input type="text" placeholder="结束日期" name="endDate" class="form-control pull-right" id="datepicker-end" value="${(orderSearch.endDate?string('yyyy-MM-dd'))!}">
						</div>
					</div>

					<div class="btn-group">
						<button type="submit" class="btn btn-primary" data-btn-type="search">查询</button>
						<button type="button" class="btn btn-default" data-btn-type="reset" onclick="javascript:$('#form')[0].reset();">重置</button>
					</div>
					</div>
			</form>

        <@shiro.hasPermission name="system:order:add">
			<a class="btn btn-sm btn-success" href="/order/add">新增</a>
        </@shiro.hasPermission>
		</div>
		<div class="box-body">
			<table class="table table-striped">
				<tr>
					<th>主键</th>
					<th>分站ID</th>
					<th>订单号</th>
					<th>总金额</th>
					<th>订单类型</th>
					<th>订单子类型</th>
					<th>订单状态</th>
					<th>创建时间</th>
					<#--<th>支付时间</th>-->
					<th>支付类型</th>
					<th>操作</th>
				</tr>
                <#list pageInfo.list as item>
                <tr>
					<td >${item.id!}</td>
					<td >${item.agentId!}</td>
					<td >${item.orderNo!}</td>
					<td >${item.amount?string('0.00')!}</td>
					<td >
						<#if item.type??>
							${convert('SERVICE_CLASS',item.type) !}
						</#if>
					</td>
					<td >
						<#if item.type??>
							<#if item.childType??>
								${convert('SERVICE_CLASS',item.type,item.childType) !}
							</#if>
						</#if>
					</td>
					<td >${convert('ORDER_STATUS',item.status) !}</td>
					<td >${item.createAt?string('yyyy-MM-dd HH:mm:ss')!}</td>
				<#--	<td >${item.payAt!}</td>-->
					<td >${convert('PAY_TYPE',item.payType) !}</td>
					<td>
					<@shiro.hasPermission name="orders:order:detail">
						<a class="btn btn-sm btn-success" href="/order/detail/${item.id}" data-btn-type="detail">详情</a>
					</@shiro.hasPermission>
                    <#--<@shiro.hasPermission name="orders:order:edit">
                        <a class="btn btn-sm btn-primary" href="/order/edit/${item.id}" data-btn-type="edit">编辑</a>
                    </@shiro.hasPermission>-->
                    <@shiro.hasPermission name="orders:order:delete">
                        <#--<button class="btn btn-sm btn-danger" onclick="del('${item.id}')">删除</button>-->
                    </@shiro.hasPermission>
					</td>
				</tr>
                </#list>
			</table>
		</div>
		<!-- /.box-body -->
		<div class="box-footer clearfix">
            <@macro.page pageInfo=pageInfo url="/order/index?" />
		</div>
	</div>
	<!-- /.box -->

</section>
<!-- /.content -->
</@layout>
